package lims.cloud.system.base.restClient;

import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Service;

@Service
public class RestServiceImpl implements RestService {

    private final LoadBalancerClient loadBalancerClient;

    public RestServiceImpl(LoadBalancerClient loadBalancerClient) {
        this.loadBalancerClient = loadBalancerClient;
    }

    @Override
    public String getUri(String applicationName, String path) {
        ServiceInstance serviceInstance = loadBalancerClient.choose("lims-cloud-" + applicationName);
        return String.format("http://%s:%s%s", serviceInstance.getHost(), serviceInstance.getPort(), path);
    }
}
